package com.leetcode.LeetCode精选TOP面试题;

/**
 * @author 覃国强
 * @date 2022-05-27 12:01
 */
public class 题库_0066_加一 {

  static
  class Solution {
    public int[] plusOne(int[] digits) {
      if (digits == null || digits.length == 0) {
        return new int[0];
      }
      for (int i = digits.length - 1; i >= 0; --i) {
        if (digits[i] == 9) {
          digits[i] = 0;
        } else {
          digits[i] += 1;
          break;
        }
      }
      if (digits[0] == 0) {
        digits = new int[digits.length + 1];
        digits[0] = 1;
      }
      return digits;
    }
  }

}
